<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no"/>
    <title>下单</title>
    <script src="__WECHAT__/js/jquery.min.js"></script>
    <link rel="stylesheet" href="__WECHAT__/css/style.css">
    <link rel="stylesheet" href="__TAOKE__/css/order.css">
    <script src="__WECHAT__/vendors/layer/layer.js"></script>
</head>
<body>

<div class="page page-main">
    <div class="confirmOrder">
        <div class="order-address mui-flex align-center">
            <div class="cell fixed align-center">
                <div class="icon"></div>
            </div>
            <div class="cell content">
                <div class="info">
                    <span>收货人：</span>
                    <span>{$user.username}</span>
                    <span></span>
                    <span class="tel">{$user.phone}</span>
                </div>

                <div class="detail">
                    <span>收货地址：</span>
                    <span>{$user.region}</span>
                    <span>{$user.address}</span>
                </div>
            </div>
            <div class="cell fixed align-center">
                <div class="nav"></div>
            </div>
        </div>

        <div class="order-order">
            <div class="order-item">
                <div class="order-itemInfo mui-flex">
                    <div class="cell fixed item-pic">
                        <div class="img-cell">
                            <div class="img" style="background-image:url({$item.pic_url});"></div>
                        </div>
                    </div>

                    <div class="content cell">
                        <div class="title">{$item.title}</div>
                        <div class="sku-info">
                            <span>{$sku_name}</span>
                        </div>
                    </div>

                    <div class="ext cell fixed item-pay">
                        <div class="price">{$item.org_price}</div>
                        <div class="quantity"><span>X</span><span>1</span></div>
                    </div>

                </div>
            </div>

            <div class="buy-single-row label-input order-memo input">
                <label class="mui-flex align-center">
                    <div class="cell fixed title input-label mui-flex align-center">
                        <div class="cell fixed">给卖家留言：</div>
                    </div>
                    <div class="cell">
                        <input placeholder="选填:填写内容已和卖家协商确认" class="remark" value="" pattern="">
                    </div>
                </label>
                <div class="seperator-wrap"><hr class="seperator"></div>
            </div>

            <div class="order-orderPay buy-single-row">
                <div class="line">
                    <span>共1件,合计:</span>
                    <div class="price">{$item.org_price}</div>
                </div>
            </div>
        </div>

        <div class="order-submitOrder">
            <div class="mui-flex align-center">
                <div class="cell realPay">
                    <div class="realPay-wrapper">
                        <span>共1件,支付积分:</span>
                        <span class="price"><span>{$item.org_price}</span></span>
                    </div>
                </div>
                <div class="cell fixed action">
                    <div class="mui-flex align-center">
                        <div title="提交订单" class="addOrder">提交订单</div>
                    </div>
                </div>
            </div>
        </div>

    </div>
</div>

<script src="__TAOKE__/js/pay.js" type="text/javascript"></script>
<script src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js" type="text/javascript"></script>
<script type="text/javascript">
    var address_url = '{:url('wechat/User/detail')}';
    var add_order_url = '{:url('wechat/Order/add')}';
    var order_list_url = '{:url('wechat/User/order')}';
    var pay_url = '{:url('wechat/Order/callPay')}';

    var address = new Array();
    var order_data = {};

    $(function () {

        address['username'] = '{$user.username}';
        address['phone'] = '{$user.phone}';
        address['region'] = '{$user.region}';
        address['address'] = '{$user.address}';

        order_data['item_id'] = '{$item.id}';
        order_data['item_name'] = '{$item.title}';
        order_data['goods_id'] = '{$item.item_id}';
        order_data['money'] = '{$item.org_price}';
        order_data['sku_id'] = '{$sku_id}';
        order_data['sku_name'] = '{$sku_name}';

        order_data['remark'] = $('.remark').val();

        function addressCheck() {
            for(var i = 0,len = address.length; i < len; i++){
                if(address[i] == ''){
                    layer.open({
                        content: '请补全收货地址',
                        skin: 'msg',
                        time: 1.5,
                        end: function () {
                            window.location.href = address_url;
                        }
                    });
                    return false;
                }
            }
            order_data['username'] = '{$user.username}';
            order_data['phone'] = '{$user.phone}';
            order_data['address'] = '{$user.region}' + '{$user.address}';
            return true;
        }

        /**
         * 添加订单
         * @param order_data
         */
        function addOrder() {

            layer.open({
                type: 2,
                content: '订单创建中',
                shadeClose: false,
            });

            $.post(add_order_url,order_data,function (result) {
                if(result.code == 200){
                    callPay(result.data);  //发起支付
                }else{
                    layer.closeAll();
                    layer.open({
                        content:result.message,
                        skin: 'msg',
                        time: 2
                    });
                }
            });
        }

        $('.addOrder').click(function () {
            addressCheck();
            addOrder();
        });
    });

</script>

</body>
</html>